package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.weixing.mall.provider.mapper.ProductStockReportMapper;
import com.weixing.mall.provider.model.domain.ProductStock;
import com.weixing.mall.provider.model.domain.ProductStockReport;
import com.weixing.mall.provider.service.IProductStockReportService;
import com.weixing.mall.provider.service.IProductStockService;
import com.weixing.mall.util.ListUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 仓库模块-商品库存表统计专用 服务实现类
 * </p>
 *
 * @author Small
 * @since 2020-06-01
 */
@Service
public class ProductStockReportServiceImpl extends ServiceImpl<ProductStockReportMapper, ProductStockReport> implements IProductStockReportService {
    @Autowired
    private IProductStockService productStockService;
    @Override
    public void updateSynData(String yearMonth) {
        List<ProductStock> list = productStockService.list();
        List<ProductStockReport> list2 = Lists.newArrayList();
        list.forEach(ps -> {
            ProductStockReport psr = new ProductStockReport();
            BeanUtils.copyProperties(ps,psr);
            psr.setYearMonthStr(yearMonth);
            list2.add(psr);
        });
       if(list2.size() > 0){
           saveBatch(list2, ListUtil.SIZE);
       }
    }
}
